import { Component } from 'react';

import { Toast, Button, Group, TextField} from 'saltui';
import DB from '../../../app/db';
import './PageHome.less';
import SelectMember from 'components/selectMember';

export default class PageHome extends Component {


 constructor(props) {
    super(props);

    //关闭加载页的遮罩效果
    $(".loading-containter").hide();
    
    let memoId = this.props.params.memoId;
    var thirdMenuType = getLoginUserInfo().thirdMenuType;
    this.state = {
      memoId:memoId,
      jsonStrTransmiScope:'',
      thirdMenuType:thirdMenuType
    };

    
    if(thirdMenuType == 'DING'){
      dd.biz.navigation.setTitle({
          title : "转发",//控制标题文本，空字符串表示显示默认文本
          onSuccess : function(result) {},
          onFail : function(err) {}
      });
    }else if(thirdMenuType =='MH'){
      !!emp&&emp.window.setTitle({
          title: {
              text: "转发",
              icon: '',
              actionmenu: {}
          },
      });
    }

  }
  
  submit(){
    let t = this;
    let jsonStrTransmiScope = this.state.jsonStrTransmiScope;
    if (jsonStrTransmiScope=="" || jsonStrTransmiScope==null || jsonStrTransmiScope==undefined || jsonStrTransmiScope.length==0) {
      Toast.show({
        type: 'error',
        content: '请选择接收范围',
        onHide: function () {
        }
      });
      return;
    }else{
      jsonStrTransmiScope = JSON.stringify(jsonStrTransmiScope);
    }
    let param = {
      memoId:this.state.memoId,
      jsonStrTransmiScope:jsonStrTransmiScope
    }

    DB.SomeModuleAPI.transmitMemo(param).then((content) => {
      //返回至列表页面
      setTimeout(function(){
        history.back();
      },2000);
      Toast.show({
        type: 'success',
        content: '转发成功',
      });
    }).catch((error) => {
      if(typeof(error.errorMsg) == 'undefined'){
        Toast.show({
          type: 'error',
          content: '转发出错'
        });
      }else{
        Toast.show({
          type: 'error',
          content: error.errorMsg
        });
      }
    });
  }
  
  cancel(){
    history.back();
  }

  changeSelectMember(newValue){
    this.setState({
      jsonStrTransmiScope: newValue
    });
  }

  render() {
    let t = this;
    return (
      <div>
          <div>
           <Group.List>
              <SelectMember
                required={true}
                readOnly={false}
                label="接收范围"
                placeholder="请选择接收范围"
                code="user,org"
                checkType="checkbox"
                isDelete={true}
                showType="list"
                onChange={this.changeSelectMember.bind(this)}
              />
            </Group.List>
          </div>
          <div >
              <Button.Group >
                  <Button type="primary" display="inline" onClick={this.submit.bind(this)}>确定</Button>
                  <Button type="secondary" display="inline" onClick={this.cancel.bind(this)}>取消</Button>             
              </Button.Group>
          </div>
      </div>
    );
  }
}


